<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-8-15
 * Time: 上午9:24
 */

namespace common\models\db;


use common\components\tools\ArrayHelper;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;

class EquipmentAppVersion extends \common\models\db\tables\EquipmentAppVersion
{
    const STATUS_DEFAULT = 10;
    const MUST_UPDATE_TRUE = 1;
    const MUST_UPDATE_FALSE = 0;

    public static function getStatusKvs()
    {
        return [
            self::STATUS_DEFAULT => '默认',
        ];
    }

    public static function getMustUpdateKvs()
    {
        return [
            self::MUST_UPDATE_FALSE => "不用强制更新",
            self::MUST_UPDATE_TRUE => "需要强制更新",
        ];
    }

    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::class,
                'updatedAtAttribute' => false,
            ],
            'blameable' => [
                'class' => BlameableBehavior::class,
                'updatedByAttribute' => false,
            ],
        ];
    }

    public function rules()
    {
        $PR = parent::rules();
        $x = $PR;
        if (in_array('required', $x[0])){
            if (is_array($x[0][0])){
                $x[0][0] = array_diff($x[0][0], ['created_at', 'created_by', 'updated_at', 'updated_by']);
            }
        }
        $y = [
            [['download_url'], 'url'],
        ];
        $x = ArrayHelper::merge($x, $y);
        return $x;
    }
}